Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
"TypeError: $ is not a function" when trying to use cheerio like jquery

I am trying to make a bot to check if an item is in stock. I based it off of this video https://www.youtube.com/watch?v=57TEZq8O360, but changed the url. Although I can console.log the content of the webpage when I try to use cheerio like jquery I get this error "TypeError: $ is not a function". I know cheerio is installed and works as I have declared it with "const $ = require('cheerio');" and have been able to use it elsewhere in my file. Is there a typo that I am missing? My broken code is below.

async function checkStock(page){
await page.reload();
let content = await page.evaluate(() => document.body.innerHTML);
console.log(content);
$("link[itemprop='availability']", content).each(function(){ //error here
    let instock= $(this).attr('href').toLowerCase().includes("outofstock");
     if(instock){
        console.log("no"); 
  }
});}



    
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to load the HTML into cheerio, and then cheerio will give you the $ API:

const $ = require("cheerio");

// ...

async function checkStock(page){
    await page.reload();
    const content = await page.evaluate(() => document.body.innerHTML);
    const $ = cheerio.load(content);

    $("link[itemprop='availability']", content).each(function(){ //error here
        let instock = $(this).attr('href').toLowerCase().includes("outofstock");
        if (instock) {
            console.log("no"); 
        }
    });
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda